home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
bit
/
src
/
mpeg
/
other.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
3KB
|
139 lines
#include <stdio.h>
#include <stdlib.h>
#include "video.h"
#include "proto.h"
extern FILE *input;
extern int EOF_flag, seek_only;
/*
*--------------------------------------------------------------
*
* DoDitherImage --
*
* Called when image needs to be dithered. Selects correct
* dither routine based on info in ditherType.
*
* Results:
* None.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
void
DoDitherImage(l, Cr, Cb, disp, h, w)
unsigned char *l, *Cr, *Cb, *disp;
int h, w;
{
if (!seek_only)
ColorDitherImage(l, Cr, Cb, disp, h, w);
}
/*
*--------------------------------------------------------------
*
* get_more_data --
*
* Called by correct_underflow in bit parsing utilities to
* read in more data.
*
* Results:
* Input buffer updated, buffer length updated.
* Returns 1 if data read, 0 if EOF, -1 if error.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
int
get_more_data(buf_start, max_length, length_ptr, buf_ptr)
unsigned int *buf_start;
int max_length;
int *length_ptr;
unsigned int **buf_ptr;
{
int length, num_read, i, request;
unsigned char *buffer, *mark;
unsigned int *lmark;
if (EOF_flag)
return 0;
length = *length_ptr;
buffer = (unsigned char *) *buf_ptr;
if (length > 0)
{
memcpy((unsigned char *) buf_start, buffer, (length * 4));
mark = ((unsigned char *) (buf_start + length));
}
else
{
mark = (unsigned char *) buf_start;
length = 0;
}
request = (max_length - length) * 4;
num_read = fread(mark, 1, request, input);
/* Paulo Villegas - 26/1/1993: Correction for 4-byte alignment */
{
int num_read_rounded;
unsigned char *index;
num_read_rounded = 4 * (num_read / 4);
/* this can happen only if num_read<request; i.e. end of file reached */
if (num_read_rounded < num_read)
{
num_read_rounded = 4 * (num_read / 4 + 1);
/* fill in with zeros */
for (index = mark + num_read; index < mark + num_read_rounded; *(index++) = 0) ;
/* advance to the next 4-byte boundary */
num_read = num_read_rounded;
}
}
if (num_read < 0)
{
return -1;
}
else if (num_read == 0)
{
*buf_ptr = buf_start;
/*
* Make 32 bits after end equal to 0 and 32 bits after that equal
* to seq end code in order to prevent messy data from infinite
* recursion.
*/
*(buf_start + length) = 0x0;
*(buf_start + length + 1) = SEQ_END_CODE;
EOF_flag = 1;
return 0;
}
lmark = (unsigned int *) mark;
num_read = num_read / 4;
for (i = 0; i < num_read; i++)
{
*lmark = htonl(*lmark);
lmark++;
}
*buf_ptr = buf_start;
*length_ptr = length + num_read;
return 1;
}